
#!/usr/bin/env bash

set -ex

function cleanup {
    rc=$?
    [ $rc -ne 0 ] && echo "==============script/check.sh failed=================="
    exit $rc
}
trap cleanup EXIT

if [ ! -x "$(type -p golangci-lint)" ]; then
    echo "golangci-lint not installed ?"
    echo "find golangci-lint install guide on https://github.com/golangci/golangci-lint"
    exit 1
fi

find . -name "*.go" -not -path "./vendor/*" -not -path "./git/*" -not -path "*/mock/*" | xargs gofmt -w

if [ "$RUN_IN_TRAVIS" != "true" ]; then
    find . -name "*.go" -not -path "./vendor/*" -not -path "./git/*" -not -path "*/mock/*" | xargs goimports -w -local matrixport/risk-control-api
fi

test -z "$(golangci-lint run -c .golangci.yaml ./... 2>&1 | grep -v 'ALL_CAPS\|OP_' 2>&1 | tee /dev/stderr)"


